import axios from 'axios'
import { BASE_URL, isDev } from 'common/config'


/**
 * 请求封装
 * @param options axios请求配置对象
 * @returns 
 */
export default function request(options: Object) {
    const install = axios.create({
        baseURL: isDev ? '' : BASE_URL,
        timeout: 5000
    })

    install.interceptors.request.use(config => config, err => Promise.reject(err))

    install.interceptors.response.use(response => {
        const { data: { code, data } } = response 
        return response.data
    }, err => Promise.reject(err))

    return install(options)
}